//
//  TicketScrollView.m
//  EasyToo
//
//  Created by Jr Lan on 13-9-3.
//
//

#import "TicketScrollView.h"

@implementation TicketScrollView
{
    NSMutableArray *namelist;
    NSMutableArray *idnumlist;
    
    UIButton *_payBtn1;
    UIButton *_payBtn2;
    
    NSInteger _payType;
}

- (void)dealloc
{
    [_payBtn1 release];
    [_payBtn2 release];
    
    _payBtn1 = nil;
    _payBtn2 = nil;
    
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        namelist = [[NSMutableArray alloc]init];
        idnumlist = [[NSMutableArray alloc]init];
        
        [namelist addObject:@"毛哲"];
        [namelist addObject:@"胜钦"];
        [namelist addObject:@"远弟"];
        
        [idnumlist addObject:@"12121212121212121"];
        [idnumlist addObject:@"34343434343434344"];
        [idnumlist addObject:@"56565656565656565"];
        
        //初始化视图
        [self init_view];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

//初始化视图
- (void)init_view
{
    //初始化票务
    int i;
    for (i  = 0; i < [namelist count]; i ++) {
        UIButton *bgBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        bgBtn.frame = CGRectMake(10, 20+i*90, 300, 80);
        [bgBtn setBackgroundImage:[UIImage imageNamed:@"couponbg"] forState:UIControlStateNormal];
        [self addSubview:bgBtn];
        
        UIButton *delBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        delBtn.frame = CGRectMake(30, 50+i*90, 20, 20);
        [delBtn addTarget:self action:@selector(delEvent) forControlEvents:UIControlEventTouchUpInside];
        [delBtn setBackgroundImage:[UIImage imageNamed:@"cp_ssshanchu"] forState:UIControlStateNormal];
        [self addSubview:delBtn];
        
        UILabel *pricelbl = [[[UILabel alloc]initWithFrame:CGRectMake(60, 30+90*i, 200, 30)]autorelease];
        pricelbl.backgroundColor = [UIColor clearColor];
        pricelbl.text = [namelist objectAtIndex:i];
        pricelbl.font = [UIFont systemFontOfSize:20];
        [self addSubview:pricelbl];
        
        UILabel *idnumlbl = [[[UILabel alloc]initWithFrame:CGRectMake(60, 60+90*i, 200, 30)]autorelease];
        idnumlbl.backgroundColor = [UIColor clearColor];
        idnumlbl.text = [idnumlist objectAtIndex:i];
        idnumlbl.font = [UIFont systemFontOfSize:20];
        [self addSubview:idnumlbl];
    }
    
    //初始化支付视图
    [self initPayView:[namelist count]];
}


//初始化支付视图
- (void)initPayView:(NSInteger)index
{
    UIButton *addTicketBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    addTicketBtn.frame = CGRectMake(20, 20+index*90, 280, 30);
    [addTicketBtn setBackgroundImage:[UIImage imageNamed:@"xyb"] forState:UIControlStateNormal];
    [addTicketBtn setTitle:@"继续添加乘机人" forState:UIControlStateNormal];
    [self addSubview:addTicketBtn];
    [addTicketBtn addTarget:self action:@selector(addticketEvent) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *paylbl = [[[UILabel alloc]initWithFrame:CGRectMake(30, 60+index*90, 180, 30)]autorelease];
    paylbl.text = @"选择支付方式:";
    paylbl.backgroundColor = [UIColor clearColor];
    [self addSubview:paylbl];
    
    _payBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(30, 100+index*90, 100, 30)];
    //[payBtn1 setBackgroundImage:[UIImage imageNamed:@"zfb"] forState:UIControlStateNormal];
    [_payBtn1 setBackgroundImage:[UIImage imageNamed:@"zhifubao2"] forState:UIControlStateNormal];
    //[payBtn1 addTarget:self action:@selector(pay1ButtonPick:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:_payBtn1];
    
    _payBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(200, 100+index*90, 100, 30)];
    //[_payBtn2 setBackgroundImage:[UIImage imageNamed:@"yinlian1"] forState:UIControlStateNormal];
    [_payBtn2 setBackgroundImage:[UIImage imageNamed:@"yinlian2"] forState:UIControlStateNormal];
    //[_payBtn2 addTarget:self action:@selector(pay2ButtonPick:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:_payBtn2];
    
    
    UIButton *nextStepBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    nextStepBtn.frame = CGRectMake(20, 140+index*90, 280, 30);
    [nextStepBtn setBackgroundImage:[UIImage imageNamed:@"xyb"] forState:UIControlStateNormal];
    [nextStepBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [self addSubview:nextStepBtn];
    
    [nextStepBtn addTarget:self action:@selector(nextEvent) forControlEvents:UIControlEventTouchUpInside];
}

-(void)pay1ButtonPick:(id)sender
{
    [_payBtn1 setSelected:YES];
    [_payBtn2 setSelected:NO];
    _payType = 0;
}

-(void)pay2ButtonPick:(id)sender
{
    [_payBtn1 setSelected:NO];
    [_payBtn2 setSelected:YES];
    _payType = 1;
}

//点击下一步
- (void)nextEvent
{
    [self.delegate onClickNextItem];
}

//继续添加机票
- (void)addticketEvent
{
    [self.delegate onclickAddItem];
}

//删除机票
- (void) delEvent
{
    [self.delegate onclickDeleteItem];
}

@end


